package com.hh.resttemplate.controller;

import com.hh.resttemplate.domain.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @GetMapping("/testGet")
    public String get(String name) {
        System.out.println("name = " + name);
        return "ok";
    }

    /**
     * POST 常用的两种传参数的方式
     * application/json
     * json 参数的核心是在请求头里面有个 content-type
     * @return
     */
    @PostMapping("/testPost")
    public String post(@RequestBody User user) {
        System.err.println("user = " + user);
        return "ok";
    }

    /**
     * 接收表单参数
     * <form action=...></form>
     * content-type = x-www-from-urlencoded
     * @return
     */
    @PostMapping("/testPost1")
    public String post1(User user) {
        System.err.println("user = " + user);
        return "ok";
    }
}
